﻿#include "URobotMainUi.h"
#include "CRobTemplateMngDlg.h"
#include "CRobTaskMngDialog.h"
#include "CRobWayPlanDialog.h"
#include "CTaskExecQueryDlg.h"

URobotMainUi::URobotMainUi(QWidget *parent)
{
	HWND hwnd = reinterpret_cast<HWND>(winId());
	setNativeTitleBar(hwnd, RGB(56, 63, 81));  // 深灰色
	ui.setupUi(this);
	//设置窗口为最大化状态
	setWindowState(windowState() | Qt::WindowMaximized);
	//配置定时器
	m_pTimer = new QTimer(this);
	m_pTimer->setTimerType(Qt::TimerType::PreciseTimer);
	connect(m_pTimer, &QTimer::timeout, this, &URobotMainUi::slotDataRefresh);
	m_pTimer->start(1000);
}

URobotMainUi::~URobotMainUi()
{
}

void URobotMainUi::initUI(QString sGuid, CDevBase * pDev, CRBaseData * pRBaseData)
{
	setStyleSheet(setUiStyle("main"));
	QString sCardStr = setUiStyle("card");
	setUi(ui.widget_MainInfo, sCardStr);
	setUi(ui.widget_State, sCardStr);
	setUi(ui.widget_Video, sCardStr);
	setUi(ui.widget_Ctr, sCardStr);
	setUi(ui.widget_Mode, sCardStr);
	setUi(ui.widget_Map, sCardStr);
	setUi(ui.widget_TableInfo, sCardStr);
	m_sGuid = sGuid;
	m_pDevHy = (CDevHy *)pDev;
	m_pBaseData = pRBaseData;
	ui.widget_Ctr->initPanel(sGuid, pDev, pRBaseData);
	ui.widget_MainInfo->initPanel(sGuid, pDev, pRBaseData);
	ui.widget_Map->initPanel(sGuid, pDev, pRBaseData);
	ui.widget_Mode->initPanel(sGuid, pDev, pRBaseData);
	ui.widget_State->initPanel(sGuid, pDev, pRBaseData);
	ui.widget_Video->initPanel(sGuid, pDev, pRBaseData);
	ui.widget_TableInfo->initPanel(sGuid, pDev, pRBaseData);
	ui.widget_Ctr->refreshData(true);
	ui.widget_MainInfo->refreshData(true);
	ui.widget_Map->refreshData(true);
	ui.widget_Mode->refreshData(true);
	ui.widget_State->refreshData(true);
	//ui.widget_Video->refreshData(true);
	ui.widget_TableInfo->refreshData(true);
	initConnect();
}

void URobotMainUi::resizeEvent(QResizeEvent * event)
{
	//QSize size = this->size();       // 当前窗口尺寸
	/*int width = this->width();       // 当前窗口宽度
	int height = this->height();     // 当前窗口高度
	double dWidth = width/VIDEOWIDTH;
	double dHeight = height/VIDEOHEIGH;
	ui.widget_Video->setFixedSize(dWidth,dHeight);*/
}

void URobotMainUi::initConnect()
{
	connect(ui.action_12, &QAction::triggered, this, &URobotMainUi::slotMapMng);
	connect(ui.action_11, &QAction::triggered, this, &URobotMainUi::slotTemplate);
	connect(ui.action_7, &QAction::triggered, this, &URobotMainUi::slotTaskMng);
	connect(ui.action_17, &QAction::triggered, this, &URobotMainUi::slotTaskInfo);
}

void URobotMainUi::setUi(QWidget * pWidget, QString sUiStr)
{
	QString sMyqss = pWidget->styleSheet();
	QString sMerged = sUiStr + "\n" + sMyqss; // 后面的会覆盖前面的相同规则
	pWidget->setAttribute(Qt::WA_StyledBackground, true);
	pWidget->setStyleSheet(sMerged);
}

void URobotMainUi::slotMapMng()
{
	CRobWayPlanDialog oper(m_sGuid, m_pDevHy, m_pBaseData);
	oper.exec();
}

void URobotMainUi::slotTemplate()
{
	CRobTemplateMngDlg oper(m_sGuid, m_pBaseData);
	oper.exec();
}

void URobotMainUi::slotTaskMng()
{
	CRobTaskMngDialog oper(m_sGuid, m_pBaseData);
	oper.exec();
}

void URobotMainUi::slotTaskInfo()
{
	CTaskExecQueryDlg oper(m_sGuid, m_pBaseData);
	oper.exec();
}


void URobotMainUi::slotDataRefresh()
{
}
